/**
 * MIT License
 * 
 * Copyright (c) 2024 - present @ ebraid
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef __EB_SHELL_H__
#define __EB_SHELL_H__


#include <list.h>
#include <types.h>
#include <drivers/uart.h>


#define SHELL_COLOR_NONE                           "\033[0m"
#define SHELL_COLOR_RED                            "\033[31m"
#define SHELL_COLOR_GREEN                          "\033[32m"
#define SHELL_COLOR_YELLOW                         "\033[33m"
#define SHELL_COLOR_BLUE                           "\033[34m"
#define SHELL_COLOR_PURPLE                         "\033[35m"
#define SHELL_COLOR_CYAN                           "\033[36m"
#define SHELL_COLOR_WHITE                          "\033[37m"
#define SHELL_COLOR_LIGHT_BLUE                     "\033[1;34m"


/**
 * @brief shell command struct
 * @node: list node
 * @name: command name
 * @desc: command description
 * @exec: command execute function
 */
typedef struct shell_cmd {
    list_node_t node;
    const char* name;
    const char* desc;
    int (*exec)(int argc, char **argv);

}shell_cmd_t;


/**
 * @brief get shell command list head
 * @param none
 * @return shell command list head
 */
list_node_t* shell_get_list_head(void);


/**
 * @brief bind uart device to shell
 * @param dev uart device
 * @return none
 */
void shell_bind_uart_device(struct uart_device *dev);


/**
 * @brief get shell device
 * @param none
 * @return shell device
 */
struct uart_device* shell_device(void);


/**
 * @brief shell command token handler
 * @param none
 * @return none
 * @note you should call this function in your uart interrupt handler
 */
void shell_token_handler(void);


/**
 * @brief shell command register
 * @param cmd shell command
 * @return int, 0: success, -1: failed
 */
int shell_cmd_register(shell_cmd_t *cmd);


/**
 * @brief shell command unregister
 * @param cmd shell command
 * @return none
 */
void shell_cmd_unregister(shell_cmd_t *cmd);


/**
 * @brief shell command loop function
 * @param none
 * @return none
 * @note you should call this function in your main loop or thread function
 */
void shell_loop(void);


#endif // !__EB_SHELL_H__
